package com.duoduo.algs4.util;

import org.joor.*;

import com.duoduo.homework.h1.PointInterval;
import com.duoduo.visual.DrawArray;

import edu.princeton.cs.algs4.Stopwatch;
import edu.princeton.cs.introcs.StdOut;

public class RepeatedlyRunningLoader {

	private int trials;
	private int initN;
	private int gap;
	private String cls;
	private double[] runningTimes;

	private String method;

	public void config(String cls, int trials, int initN, int gap, String method) {
		this.cls = cls;
		this.trials = trials;
		this.initN = initN;
		this.gap = gap;
		this.method = method;

	}

	public double[] getRunningTimes() {
		return runningTimes;
	}

	public void run() {
		int N = initN;
		runningTimes = new double[trials];
		Stopwatch timer;
		for (int i = 0; i < trials; i++) {
			N = initN + gap * i;
			timer = new Stopwatch();
			Reflect.on(cls).create(N).call(method);
			runningTimes[i] = timer.elapsedTime();
			StdOut.print(String.format(
					"【进行%d组测试】当前为第%d组：测试信息\n 用例%d 时间为%7.5f\n", trials, i, N,
					runningTimes[i]));
		}
	}

	public void run(String name) {
		run();
		DrawArray.DrawArrayUsePoints(runningTimes, runningTimes[trials - 1],
				name);
	}

	public static void main(String[] args) {
		RepeatedlyRunningLoader loader = new RepeatedlyRunningLoader();
		loader.config(PointInterval.class.getName(), 150, 100, 200,
				"calculateShortestPoint");
		loader.run("测试");

	}

}
